package cn.scxy.bookcity.controller;

import cn.scxy.bookcity.mapper.UserIndexMapper;
import cn.scxy.bookcity.pojo.dto.UserLoginDTO;
import cn.scxy.bookcity.pojo.entity.Notice;
import cn.scxy.bookcity.pojo.entity.PmsCategory;
import cn.scxy.bookcity.pojo.vo.*;
import cn.scxy.bookcity.service.IUserIndexService;
import cn.scxy.bookcity.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 用户首页的控制器
 * @author zzr
 */
@RestController
@RequestMapping("/indexs")
@Api(tags = "用户首页,公用")
@Slf4j
public class UserIndexController {
    @Autowired
    IUserIndexService service;
    @ApiOperation("根据父类id查询中间级类别列表")
    @ApiOperationSupport(order = 302)
    @GetMapping("/{id}/selectCategoryById")
    public JsonResult<List<ZZRCategoryListVOZZR>> selectCategoryById(@PathVariable Long id){
        System.out.println(service.selectCategoryById(id));
        List<ZZRCategoryListVOZZR> list = service.selectCategoryById(id);
        return JsonResult.ok(list);
    }
    @ApiOperation("根据中间级类id查询孙子级类别列表")
    @ApiOperationSupport(order = 303)
    @GetMapping("/{id}/selectCategoryChildrenById")
    public JsonResult<List<ZZRCategoryListVOZZR>> selectCategoryChildrenById(@PathVariable Long id){
        System.out.println(service.selectCategoryChildrenById(id));
        List<ZZRCategoryListVOZZR> list = service.selectCategoryChildrenById(id);
        return JsonResult.ok(list);
    }
    @ApiOperation("查询中间级类别列表")
    @ApiOperationSupport(order = 300)
    @GetMapping("/selectCategory")
    public JsonResult<List<ZZRCategoryListVOZZR>> selectCategory(){
        System.out.println(service.selectCategory());
        List<ZZRCategoryListVOZZR> list = service.selectCategory();
        return JsonResult.ok(list);
    }
    @ApiOperation("查询父级类别列表")
    @ApiOperationSupport(order = 303)
    @GetMapping("/selectCategoryParent")
    public JsonResult<List<ZZRCategoryListVOZZR>> selectCategoryParent(){
        System.out.println(service.selectCategoryParent());
        List<ZZRCategoryListVOZZR> list = service.selectCategoryParent();
        return JsonResult.ok(list);
    }


    @ApiOperation("查询热搜列表")
    @ApiOperationSupport(order = 301)
    @GetMapping("/selectHotSearch")
    public JsonResult<List<HotSearchListVO>> selectHotSearchList(){
        System.out.println(service.selectHotSearchList());
        List<HotSearchListVO> list = service.selectHotSearchList();
        return JsonResult.ok(list);
    }
    @ApiOperation("根据用户id统计购物车数量")
    @ApiOperationSupport(order = 302)
    @GetMapping("/{id:[0-9]+}/countSoppingCar")
    public JsonResult<Integer> countSoppingCar(@PathVariable Long id){
        System.out.println(service.countSoppingCar(id));
        Integer i=service.countSoppingCar(id);
        return JsonResult.ok(i);
    }

    @ApiOperation("查询销量排序商品")
    @ApiOperationSupport(order = 302)
    @GetMapping("/selectGoodsListByNums")
    public JsonResult<List<GoodsListItemVO>> selectGoodsListByNums(){
        log.debug("开始查询销量排序商品controller");
        List<GoodsListItemVO> list = service.selectGoodsListByNums();
        log.debug("{}",list);
        return JsonResult.ok(list);
    }
    @ApiOperation("查询评论排序商品")
    @ApiOperationSupport(order = 305)
    @GetMapping("/selectGoodsListByComments")
    public JsonResult<List<GoodsListItemVO>> selectGoodsListByComments(){
        log.debug("开始查询销量排序商品controller");
        List<GoodsListItemVO> list = service.selectGoodsListByComments();
        log.debug("{}",list);
        return JsonResult.ok(list);
    }
    @ApiOperation("查询销量排序商品")
    @ApiOperationSupport(order = 302)
    @GetMapping("/selectGoodsListByNumsAll")
    public JsonResult<List<GoodsListItemVO>> selectGoodsListByNumsAll(){
        log.debug("开始查询销量排序全部商品controller");
        List<GoodsListItemVO> list = service.selectGoodsListByNumsAll();
        log.debug("{}",list);
        return JsonResult.ok(list);
    }
    @ApiOperation("查询全部评论排序商品")
    @ApiOperationSupport(order = 305)
    @GetMapping("/selectGoodsListByCommentsAll")
    public JsonResult<List<GoodsListItemVO>> selectGoodsListByCommentsAll(){
        log.debug("开始查询全部评论排序商品controller");
        List<GoodsListItemVO> list = service.selectGoodsListByCommentsAll();
        log.debug("{}",list);
        return JsonResult.ok(list);
    }
    @ApiOperation("查询当前登录用户")
    @ApiOperationSupport(order = 305)
    @GetMapping("/getUserLogin")
    public JsonResult<UserLoginDTO> getUserLogin(HttpSession session){
        log.debug("查询当前登录用户");
        UserLoginDTO user = service.getUserLogin(session);
        return JsonResult.ok(user);
    }
    @ApiOperation("删除当前登录用户")
    @ApiOperationSupport(order = 305)
    @GetMapping("/leaveUserLogin")
    public JsonResult<Void> leaveUserLogin(HttpSession session){
        session.removeAttribute("user");
        log.debug("删除session的用户数据，{}",session.getAttribute("user"));
        return JsonResult.ok();
    }

    @ApiOperation("查询活动")
    @ApiOperationSupport(order = 305)
    @GetMapping("/selectActivity")
    public JsonResult<List<ActivityListVO>> selectActivity(){
        log.debug("开始查询全部评论排序商品controller");
        List<ActivityListVO> list = service.selectActivity();
        log.debug("{}",list);
        return JsonResult.ok(list);
    }
 @ApiOperation("查询公告")
    @ApiOperationSupport(order = 305)
    @GetMapping("/selectNotice")
    public JsonResult<List<Notice>> selectNotice(){
        log.debug("开始查询全部评论排序商品controller");
        List<Notice> list = service.selectNotice();
        log.debug("{}",list);
        return JsonResult.ok(list);
    }

}
